﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;
namespace EmployeeCheckIn
{
    public partial class MenuAdmin : System.Web.UI.Page
    {                                                         

        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            if (Session["User"] != null && Session["Pass"] != null)
            {
               // lbNameAdmin.Text = Session["User"].ToString();

             
                if (Session["JavaCeateAdmin"] !=null)
                {
                   
                    Session["JavaCeateAdmin"] = null;
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
            if (Session["User"] != null && Session["Pass"] != null)
            {

                txtShow();
                Label1.Text = Session["User"].ToString();
                int i = Convert.ToInt32(Session["admin_id"]);
                Session["index_id"] = i;
                string chkTitle, chkStatus;
                //Selectdata sl = new Selectdata();
                DataTable dt = SelectAdminDataa(i);
                if (dt != null && dt.Rows.Count > 0)
                {
                    //lbUserName.Text = dt.Rows[0]["user_name"].ToString();
                    chkTitle = dt.Rows[0]["admin_title"].ToString();
                    lbName.Text = dt.Rows[0]["admin_name"].ToString();
                    lbLastname.Text = dt.Rows[0]["admin_lastname"].ToString();
                    //lbPhone.Text = dt.Rows[0]["admin_phone"].ToString();
                    chkStatus = dt.Rows[0]["admin_status_id"].ToString();


                    if (chkTitle == "1")
                    {
                        lbTitle.Text = "นาย";
                    }
                    if (chkTitle == "2")
                    {
                        lbTitle.Text = "นาง";
                    }
                    if (chkTitle == "3")
                    {
                        lbTitle.Text = "นางสาว";
                    }
                    if (chkStatus == "1")
                    {
                        lbStatus.Text = "Super Admin";
                    }
                    if (chkStatus == "2")
                    {
                        lbStatus.Text = "Admin";
                    }
                }
                if (IsPostBack)
                {

                }

            }
            else
            {
                Response.Redirect("Default.aspx");
                
            }

        }
        public DataTable SelectAdminDataa(int i)
        {
            string sqltext = @"select * from tbl_log_in where admin_id=" + i + "  ";


            SqlConnection sqlconn = new SqlConnection("Server=202.44.52.248;Database=DB_Personal;User Id=personal;Password=1234;");
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
        private void txtShow()  
        {
            //lbUserName.Visible = true;
            lbTitle.Visible = true;
            lbStatus.Visible = true;
            lbName.Visible = true;
            lbLastname.Visible = true;

           // lbPhone.Visible = true;
        }
        public DateTime ConvestToDate(string s)
        {
            int day = 1;
            int mount = 1;
            int years = 1111;
            try
            {
                string[] stemp = s.Split('/');
                day = Convert.ToInt32(stemp[0]);
                mount = Convert.ToInt32(stemp[1]);
                years = Convert.ToInt32(stemp[2]);
                if (years > 2300)
                {
                    years = years - 543;
                }
                return new DateTime(years, mount, day);
            }
            catch (Exception)
            {


            }

            return new DateTime(years, mount, day);

        }

        protected void btEdit_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                Server.Transfer("EditAdmin.aspx");
            }
            else
            {
                Response.Redirect("Default.aspx");
            }

        }

        protected void lkbListAdmin_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                Server.Transfer("ListAdmin.aspx");
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }

        

       
    }
}